﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TimViec.NTD
{
    public partial class UpdatePass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["NTD"] == null)
            {
                Response.Redirect("/nha-tuyen-dung.html");
            }
        }

        protected void btSave_Click(object sender, EventArgs e)
        {
            DAL.UserTuyenDung userTuyenDung = BLL.TuyenDung.UserHelper.Get_UserEmail(Session["NTD"].ToString());
            if(userTuyenDung.MatKhau != Tool.MaHoa(txtMKCu.Text))
            {
                 ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectMe", "alert('Sai mật khẩu cũ!');", true);
                return;
            }
            else
            {
                if(txtNhapLaiMKMoi.Text != txtMKMoi.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectMe", "alert('Mật khẩu mới không trùng nhau!');", true);
                    return;
                }
                BLL.TuyenDung.UserHelper.DoiMatKhau(txtMKCu.Text,txtMKMoi.Text);
                txtMKCu.Text = "";
                txtMKMoi.Text = "";
                txtNhapLaiMKMoi.Text = "";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectMe", "alert('Thay đổi mật khẩu thành công!');", true);
                
            }
        }

        protected void btCancle_Click(object sender, EventArgs e)
        {
            txtMKCu.Text = "";
            txtMKMoi.Text = "";
            txtNhapLaiMKMoi.Text = "";
        }
    }
}